const mongoose = require('mongoose')
const model = mongoose.model.bind(mongoose)
const Schema = mongoose.Schema
const ObjectId = Schema.Types.ObjectId

const systemSchema = new Schema({
   _id: ObjectId,
   systemName: String,
   brands:[{
    type:ObjectId,
    ref:'Brand'
   }]
})

const brandSchema = new Schema({
    _id:ObjectId,
    brandName:String,
    phones:[{
        type:ObjectId,
        ref:'Phone'
    }]
})

const phoneSchema = new Schema({
    name:String,
    price:String,
    created_time: {
        type: Date,
        default: Date.now 
    }
})

const System = model('System', systemSchema )
const Brand = model('Brand', brandSchema )
const Phone = model('Phone', phoneSchema)

module.exports =  { System, Brand, Phone }